﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button v-if="hasPerm('DispatchList.Add')" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
      <a-button
        v-if="hasPerm('DispatchList.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
        >删除</a-button
      >
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <a-select-option key="cCusName">客户名称</a-select-option>
                <a-select-option key="cDLCode">发货退货单号</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" @keydown.enter="getDataList" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button
              type="primary"
              @click="
                () => {
                  this.pagination.current = 1
                  this.getDataList()
                }
              "
              >查询</a-button
            >
            <a-button style="margin-left: 8px" @click="repossess">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :scroll="{ y: 530 }"
      :columns="columns"
      :rowKey="(row, index) => row + index"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :bordered="true"
      size="small"
    >
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime) }}</span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="handleEdit(record.DLID)">查看</a>
          <a-divider v-if="hasPerm('DispatchList.Edit') && hasPerm('DispatchList.Delete')" type="vertical" />
          <a v-if="hasPerm('DispatchList.Delete')" @click="handleDelete([record.Id])">删除</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import moment from 'moment'
const columns = [
  // { title: '发货退货单主表标识', dataIndex: 'DLID', width: '10%' },
  { title: '销售订单号', dataIndex: 'cSOCode', width: '10%' },
  { title: '客户编码', dataIndex: 'cCusCode', width: '10%' },
  { title: '客户名称', dataIndex: 'cCusName', width: '20%' },
  { title: '发货退货单号', dataIndex: 'cDLCode', width: '10%' },
  // { title: '单据类型', dataIndex: 'cVouchType', width: '80px' },
  // { title: '单据类型', dataIndex: 'cVouchName', width: '80px' },
  // { title: '销售类型', dataIndex: 'cSTCode', width: '80px' },
  { title: '销售类型', dataIndex: 'cSTName', align: 'center', width: '10%' },
  {
    title: '单据日期',
    dataIndex: 'dDate',
    align: 'center',
    customRender: (value, row, index) => {
      return value.substring(0, 10)
    },
    width: '8%'
  },
  // { title: '销售发票号', dataIndex: 'cSBVCode' },

  { title: '发往地址', dataIndex: 'cShipAddress', width: '25%', ellipsis: true },
  // { title: '币种名称', dataIndex: 'cexch_name' },
  // { title: '汇率', dataIndex: 'iExchRate', width: '80px' },
  // { title: '收发类别编码', dataIndex: 'cRdCode', width: '10%' },
  // { title: '组织机构编码', dataIndex: 'cDepCode', width: '10%' },
  // { title: '业务员编码', dataIndex: 'cPersonCode', width: '10%' },
  // { title: '销售发票主表标识', dataIndex: 'SBVID', width: '10%' },
  // { title: '付款条件编码', dataIndex: 'cPayCode', width: '10%' },
  // { title: '发运方式编码', dataIndex: 'cSCCode', width: '10%' },
  // { title: '表头税率', dataIndex: 'iTaxRate', width: '10%' },
  // { title: '销售期初标志', dataIndex: 'bFirst', width: '10%' },
  // { title: '退货标志', dataIndex: 'bReturnFlag', width: '10%' },
  // { title: '结算标志', dataIndex: 'bSettleAll', width: '10%' },
  // { title: '备注', dataIndex: 'cMemo', width: '10%' },
  // { title: '出库单据号字符串', dataIndex: 'cSaleOut', width: '10%' },
  // { title: '自定义项1', dataIndex: 'cDefine1', width: '10%' },
  // { title: '自定义项2', dataIndex: 'cDefine2', width: '10%' },
  // { title: '自定义项3', dataIndex: 'cDefine3', width: '10%' },
  // { title: '自定义项4', dataIndex: 'cDefine4', width: '10%' },
  // { title: '自定义项5', dataIndex: 'cDefine5', width: '10%' },
  // { title: '自定义项6', dataIndex: 'cDefine6', width: '10%' },
  // { title: '自定义项7', dataIndex: 'cDefine7', width: '10%' },
  // { title: '自定义项8', dataIndex: 'cDefine8', width: '10%' },
  // { title: '自定义项9', dataIndex: 'cDefine9', width: '10%' },
  // { title: '自定义项10', dataIndex: 'cDefine10', width: '10%' },
  // { title: '审核人', dataIndex: 'cVerifier', width: '10%' },
  // { title: '制单人', dataIndex: 'cMaker', width: '10%' },
  // { title: '现无用', dataIndex: 'iNetLock', width: '10%' },
  // { title: '是否先发货', dataIndex: 'iSale', width: '10%' },
  // { title: '单据模版号', dataIndex: 'iVTid', width: '10%' },
  // { title: '时间戳', dataIndex: 'ufts', width: '10%' },
  // { title: '业务类型', dataIndex: 'cBusType', width: '10%' },
  // { title: '关闭人', dataIndex: 'cCloser', width: '10%' },
  // { title: '记账人', dataIndex: 'cAccounter', width: '10%' },
  // { title: '信用审核人', dataIndex: 'cCreChpName', width: '10%' },
  // { title: '自定义项11', dataIndex: 'cDefine11', width: '10%' },
  // { title: '自定义项12', dataIndex: 'cDefine12', width: '10%' },
  // { title: '自定义项13', dataIndex: 'cDefine13', width: '10%' },
  // { title: '自定义项14', dataIndex: 'cDefine14', width: '10%' },
  // { title: '自定义项15', dataIndex: 'cDefine15', width: '10%' },
  // { title: '自定义项16', dataIndex: 'cDefine16', width: '10%' },
  // { title: '存货期初标志', dataIndex: 'bIAFirst', width: '10%' },
  // { title: '金税导出次数', dataIndex: 'ioutgolden', width: '10%' },
  // { title: '收付款协议', dataIndex: 'cgatheringplan', width: '10%' },
  // { title: '立账日', dataIndex: 'dCreditStart', width: '10%' },
  // { title: '到期日', dataIndex: 'dGatheringDate', width: '10%' },
  // { title: '账期', dataIndex: 'icreditdays', width: '10%' },
  // { title: '是否立账单据', dataIndex: 'bCredit', width: '10%' },
  // { title: '发货地址编码', dataIndex: 'caddcode', width: '10%' },
  // { title: '审核状态', dataIndex: 'iverifystate', width: '10%' },
  // { title: '打回次数', dataIndex: 'ireturncount', width: '10%' },
  // { title: '启用工作流', dataIndex: 'iswfcontrolled', width: '10%' },
  // { title: '信用审批状态', dataIndex: 'icreditstate', width: '10%' },
  // { title: '应收期初', dataIndex: 'bARFirst', width: '10%' },
  // { title: '修改人', dataIndex: 'cmodifier', width: '10%' },
  // { title: '修改日期', dataIndex: 'dmoddate', width: '10%' },
  // { title: '审核日期', dataIndex: 'dverifydate', width: '10%' },
  // { title: '客户联系人', dataIndex: 'ccusperson', width: '10%' },
  // { title: '制单时间', dataIndex: 'dcreatesystime', width: '10%' },
  // { title: '审核时间', dataIndex: 'dverifysystime', width: '10%' },
  // { title: '修改时间', dataIndex: 'dmodifysystime', width: '10%' },
  // { title: '来源单据类型', dataIndex: 'csvouchtype', width: '10%' },
  // { title: '流程id', dataIndex: 'iflowid', width: '10%' },
  // { title: '签回损失生成', dataIndex: 'bsigncreate', width: '10%' },
  // { title: '现款结算', dataIndex: 'bcashsale', width: '10%' },
  // { title: '收款单号', dataIndex: 'cgathingcode', width: '10%' },
  // { title: '变更人', dataIndex: 'cChanger', width: '10%' },
  // { title: '变更原因', dataIndex: 'cChangeMemo', width: '10%' },
  // { title: 'outid', dataIndex: 'outid', width: '10%' },
  // { title: '必有定金', dataIndex: 'bmustbook', width: '10%' },
  // { title: '预定组织机构编码', dataIndex: 'cBookDepcode', width: '10%' },
  // { title: '预定类型', dataIndex: 'cBookType', width: '10%' },
  // { title: '是否销售使用', dataIndex: 'bSaUsed', width: '10%' },
  // { title: '是否需要开票', dataIndex: 'bneedbill', width: '10%' },
  // { title: '存货选项切换', dataIndex: 'baccswitchflag', width: '10%' },
  // { title: '打印次数', dataIndex: 'iPrintCount', width: '10%' },
  // { title: '联系人编码', dataIndex: 'ccuspersoncode', width: '10%' },
  // { title: '来源单据号', dataIndex: 'cSourceCode', width: '10%' },
  // { title: '是否出库开票', dataIndex: 'bsaleoutcreatebill', width: '10%' },
  // { title: '表头单据条码', dataIndex: 'cSysBarCode', width: '10%' },
  // { title: '当前审批人', dataIndex: 'cCurrentAuditor', width: '10%' },
  // { title: '结算方式编码', dataIndex: 'csscode', width: '10%' },
  // { title: '开票单位编码', dataIndex: 'cinvoicecompany', width: '10%' },
  // { title: '重量', dataIndex: 'fEBweight', width: '10%' },
  // { title: '重量单位', dataIndex: 'cEBweightUnit', width: '10%' },
  // { title: '快递单号', dataIndex: 'cEBExpressCode', width: '10%' },
  // { title: '物流公司ID', dataIndex: 'iEBExpressCoID', width: '10%' },
  // { title: '分拣号', dataIndex: 'SeparateID', width: '10%' },
  // { title: '不导出到金税', dataIndex: 'bNotToGoldTax', width: '10%' },
  // { title: 'cEBTrnumber', dataIndex: 'cEBTrnumber', width: '10%' },
  // { title: 'cEBBuyer', dataIndex: 'cEBBuyer', width: '10%' },
  // { title: 'cEBBuyerNote', dataIndex: 'cEBBuyerNote', width: '10%' },
  // { title: 'ccontactname', dataIndex: 'ccontactname', width: '10%' },
  // { title: 'cEBprovince', dataIndex: 'cEBprovince', width: '10%' },
  // { title: 'cEBcity', dataIndex: 'cEBcity', width: '10%' },
  // { title: 'cEBdistrict', dataIndex: 'cEBdistrict', width: '10%' },
  // { title: 'cmobilephone', dataIndex: 'cmobilephone', width: '10%' },
  // { title: 'cInvoiceCusName', dataIndex: 'cInvoiceCusName', width: '10%' },
  // { title: 'cweighter', dataIndex: 'cweighter', width: '10%' },
  // { title: 'dweighttime', dataIndex: 'dweighttime', width: '10%' },
  // { title: 'cPickVouchCode', dataIndex: 'cPickVouchCode', width: '10%' },
  // {
  //   title: '创建时间',
  //   dataIndex: 'CreateTime',
  //   width: '10%',
  //   align: 'center',
  //   scopedSlots: { customRender: 'CreateTime' }
  // },
  { title: '操作', dataIndex: 'action', align: 'left', scopedSlots: { customRender: 'action' }, width: '8%' }
]

export default {
  components: {
    EditForm
  },
  mounted() {
    this.getDataList()
  },
  data() {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 25,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['25', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'dDate', order: 'desc' },
      loading: false,
      columns,
      queryParam: { condition: 'cCusName' },
      selectedRowKeys: []
    }
  },
  methods: {
    repossess() {
      this.queryParam = { condition: 'cCusName' }

    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }

      this.getDataList()
    },
    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/OrderManagement/DispatchList/GetDataListByMySelfCustomer', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'DLID',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    handleAdd() {
      this.$refs.editForm.openForm(null, '新建发货退货单主表信息')
    },
    handleEdit(id) {
      this.$refs.editForm.openForm(id, '详情')
    },
    handleDelete(ids) {
      var thisObj = this
      this.$confirm({
        title: '确认删除吗?',
        onOk() {
          return new Promise((resolve, reject) => {
            thisObj.$http.post('/OrderManagement/DispatchList/DeleteData', ids).then(resJson => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else {
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
        }
      })
    },
    timeFormat(val) {
      // 时间格式化函数
      return moment(val).format('YYYY-MM-DD HH:mm')
    }
  }
}
</script>
